home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / sprdgun2.zip / WEAPONS.QC < prev   
Text File  |  1996-09-25  |  28KB  |  1,309 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25. };
  26.  
  27. float() crandom =
  28. {
  29.     return 2*(random() - 0.5);
  30. };
  31.  
  32. /*
  33. ================
  34. W_FireAxe
  35. ================
  36. */
  37. void() W_FireAxe =
  38. {
  39.     local    vector    source;
  40.     local    vector    org;
  41.  
  42.     source = self.origin + '0 0 16';
  43.     traceline (source, source + v_forward*64, FALSE, self);
  44.     if (trace_fraction == 1.0)
  45.         return;
  46.     
  47.     org = trace_endpos - v_forward*4;
  48.  
  49.     if (trace_ent.takedamage)
  50.     {
  51.         trace_ent.axhitme = 1;
  52.         SpawnBlood (org, '0 0 0', 20);
  53.         T_Damage (trace_ent, self, self, 20);
  54.     }
  55.     else
  56.     {    // hit wall
  57.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  58.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  59.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  60.         WriteCoord (MSG_BROADCAST, org_x);
  61.         WriteCoord (MSG_BROADCAST, org_y);
  62.         WriteCoord (MSG_BROADCAST, org_z);
  63.     }
  64. };
  65.  
  66.  
  67. //============================================================================
  68.  
  69.  
  70. vector() wall_velocity =
  71. {
  72.     local vector    vel;
  73.     
  74.     vel = normalize (self.velocity);
  75.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  76.     vel = vel + 2*trace_plane_normal;
  77.     vel = vel * 200;
  78.     
  79.     return vel;
  80. };
  81.  
  82.  
  83. /*
  84. ================
  85. SpawnMeatSpray
  86. ================
  87. */
  88. void(vector org, vector vel) SpawnMeatSpray =
  89. {
  90.     local    entity missile, mpuff;
  91.     local    vector    org;
  92.  
  93.     missile = spawn ();
  94.     missile.owner = self;
  95.     missile.movetype = MOVETYPE_BOUNCE;
  96.     missile.solid = SOLID_NOT;
  97.  
  98.     makevectors (self.angles);
  99.  
  100.     missile.velocity = vel;
  101.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  102.  
  103.     missile.avelocity = '3000 1000 2000';
  104.     
  105. // set missile duration
  106.     missile.nextthink = time + 1;
  107.     missile.think = SUB_Remove;
  108.  
  109.     setmodel (missile, "progs/zom_gib.mdl");
  110.     setsize (missile, '0 0 0', '0 0 0');        
  111.     setorigin (missile, org);
  112. };
  113.  
  114. /*
  115. ================
  116. SpawnBlood
  117. ================
  118. */
  119. void(vector org, vector vel, float damage) SpawnBlood =
  120. {
  121.     particle (org, vel*0.1, 73, damage*2);
  122. };
  123.  
  124. /*
  125. ================
  126. spawn_touchblood
  127. ================
  128. */
  129. void(float damage) spawn_touchblood =
  130. {
  131.     local vector    vel;
  132.  
  133.     vel = wall_velocity () * 0.2;
  134.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  135. };
  136.  
  137.  
  138. /*
  139. ================
  140. SpawnChunk
  141. ================
  142. */
  143. void(vector org, vector vel) SpawnChunk =
  144. {
  145.     particle (org, vel*0.02, 0, 10);
  146. };
  147.  
  148. /*
  149. ==============================================================================
  150.  
  151. MULTI-DAMAGE
  152.  
  153. Collects multiple small damages into a single damage
  154.  
  155. ==============================================================================
  156. */
  157.  
  158. entity    multi_ent;
  159. float    multi_damage;
  160.  
  161. void() ClearMultiDamage =
  162. {
  163.     multi_ent = world;
  164.     multi_damage = 0;
  165. };
  166.  
  167. void() ApplyMultiDamage =
  168. {
  169.     if (!multi_ent)
  170.         return;
  171.     T_Damage (multi_ent, self, self, multi_damage);
  172. };
  173.  
  174. void(entity hit, float damage) AddMultiDamage =
  175. {
  176.     if (!hit)
  177.         return;
  178.     
  179.     if (hit != multi_ent)
  180.     {
  181.         ApplyMultiDamage ();
  182.         multi_damage = damage;
  183.         multi_ent = hit;
  184.     }
  185.     else
  186.         multi_damage = multi_damage + damage;
  187. };
  188.  
  189. /*
  190. ==============================================================================
  191.  
  192. BULLETS
  193.  
  194. ==============================================================================
  195. */
  196.  
  197. /*
  198. ================
  199. TraceAttack
  200. ================
  201. */
  202. void(float damage, vector dir) TraceAttack =
  203. {
  204.     local    vector    vel, org;
  205.     
  206.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  207.     vel = vel + 2*trace_plane_normal;
  208.     vel = vel * 200;
  209.  
  210.     org = trace_endpos - dir*4;
  211.  
  212.     if (trace_ent.takedamage)
  213.     {
  214.         SpawnBlood (org, vel*0.2, damage);
  215.         AddMultiDamage (trace_ent, damage);
  216.     }
  217.     else
  218.     {
  219.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  220.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  221.         WriteCoord (MSG_BROADCAST, org_x);
  222.         WriteCoord (MSG_BROADCAST, org_y);
  223.         WriteCoord (MSG_BROADCAST, org_z);
  224.     }
  225. };
  226.  
  227. /*
  228. ================
  229. FireBullets
  230.  
  231. Used by shotgun, super shotgun, and enemy soldier firing
  232. Go to the trouble of combining multiple pellets into a single damage call.
  233. ================
  234. */
  235. void(float shotcount, vector dir, vector spread) FireBullets =
  236. {
  237.     local    vector direction;
  238.     local    vector    src;
  239.     
  240.     makevectors(self.v_angle);
  241.  
  242.     src = self.origin + v_forward*10;
  243.     src_z = self.absmin_z + self.size_z * 0.7;
  244.  
  245.     ClearMultiDamage ();
  246.     while (shotcount > 0)
  247.     {
  248.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  249.  
  250.         traceline (src, src + direction*2048, FALSE, self);
  251.         if (trace_fraction != 1.0)
  252.             TraceAttack (4, direction);
  253.  
  254.         shotcount = shotcount - 1;
  255.     }
  256.     ApplyMultiDamage ();
  257. };
  258.  
  259. /*
  260. ================
  261. W_FireShotgun
  262. ================
  263. */
  264. void() W_FireShotgun =
  265. {
  266.     local vector dir;
  267.  
  268.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  269.  
  270.     self.punchangle_x = -2;
  271.     
  272.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  273.     dir = aim (self, 100000);
  274.     FireBullets (6, dir, '0.04 0.04 0');
  275. };
  276.  
  277.  
  278. /*
  279. ================
  280. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.         
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  294.  
  295.     self.punchangle_x = -4;
  296.     
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303. /*
  304. ==============================================================================
  305.  
  306. ROCKETS
  307.  
  308. ==============================================================================
  309. */
  310.  
  311. void()    s_explode1    =    [0,        s_explode2] {};
  312. void()    s_explode2    =    [1,        s_explode3] {};
  313. void()    s_explode3    =    [2,        s_explode4] {};
  314. void()    s_explode4    =    [3,        s_explode5] {};
  315. void()    s_explode5    =    [4,        s_explode6] {};
  316. void()    s_explode6    =    [5,        SUB_Remove] {};
  317.  
  318. void() BecomeExplosion =
  319. {
  320.     self.movetype = MOVETYPE_NONE;
  321.     self.velocity = '0 0 0';
  322.     self.touch = SUB_Null;
  323.     setmodel (self, "progs/s_explod.spr");
  324.     self.solid = SOLID_NOT;
  325.     s_explode1 ();
  326. };
  327.  
  328. void() T_MissileTouch =
  329. {
  330.     local float    damg;
  331.  
  332.     if (other == self.owner)
  333.         return;        // don't explode on owner
  334.  
  335.     if (pointcontents(self.origin) == CONTENT_SKY)
  336.     {
  337.         remove(self);
  338.         return;
  339.     }
  340.  
  341.     damg = 100 + random()*20;
  342.     
  343.     if (other.health)
  344.     {
  345.         if (other.classname == "monster_shambler")
  346.             damg = damg * 0.5;    // mostly immune
  347.         T_Damage (other, self, self.owner, damg );
  348.     }
  349.  
  350.     // don't do radius damage to the other, because all the damage
  351.     // was done in the impact
  352.     T_RadiusDamage (self, self.owner, 120, other);
  353.  
  354. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  355.     self.origin = self.origin - 8*normalize(self.velocity);
  356.  
  357.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  358.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  359.     WriteCoord (MSG_BROADCAST, self.origin_x);
  360.     WriteCoord (MSG_BROADCAST, self.origin_y);
  361.     WriteCoord (MSG_BROADCAST, self.origin_z);
  362.  
  363.     BecomeExplosion ();
  364. };
  365.  
  366.  
  367.  
  368. /*
  369. ================
  370. W_FireRocket
  371. ================
  372. */
  373. void() W_FireRocket =
  374. {
  375.     local    entity missile, mpuff;
  376.     
  377.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  378.     
  379.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  380.  
  381.     self.punchangle_x = -2;
  382.  
  383.     missile = spawn ();
  384.     missile.owner = self;
  385.     missile.movetype = MOVETYPE_FLYMISSILE;
  386.     missile.solid = SOLID_BBOX;
  387.         
  388. // set missile speed    
  389.  
  390.     makevectors (self.v_angle);
  391.     missile.velocity = aim(self, 1000);
  392.     missile.velocity = missile.velocity * 1000;
  393.     missile.angles = vectoangles(missile.velocity);
  394.     
  395.     missile.touch = T_MissileTouch;
  396.     
  397. // set missile duration
  398.     missile.nextthink = time + 5;
  399.     missile.think = SUB_Remove;
  400.  
  401.     setmodel (missile, "progs/missile.mdl");
  402.     setsize (missile, '0 0 0', '0 0 0');        
  403.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  404. };
  405.  
  406. /*
  407. ===============================================================================
  408.  
  409. LIGHTNING
  410.  
  411. ===============================================================================
  412. */
  413.  
  414. /*
  415. =================
  416. LightningDamage
  417. =================
  418. */
  419. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  420. {
  421.     local entity        e1, e2;
  422.     local vector        f;
  423.     
  424.     f = p2 - p1;
  425.     normalize (f);
  426.     f_x = 0 - f_y;
  427.     f_y = f_x;
  428.     f_z = 0;
  429.     f = f*16;
  430.  
  431.     e1 = e2 = world;
  432.  
  433.     traceline (p1, p2, FALSE, self);
  434.     if (trace_ent.takedamage)
  435.     {
  436.         particle (trace_endpos, '0 0 100', 225, damage*4);
  437.         T_Damage (trace_ent, from, from, damage);
  438.         if (self.classname == "player")
  439.         {
  440.             if (other.classname == "player")
  441.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  442.         }
  443.     }
  444.     e1 = trace_ent;
  445.  
  446.     traceline (p1 + f, p2 + f, FALSE, self);
  447.     if (trace_ent != e1 && trace_ent.takedamage)
  448.     {
  449.         particle (trace_endpos, '0 0 100', 225, damage*4);
  450.         T_Damage (trace_ent, from, from, damage);
  451.     }
  452.     e2 = trace_ent;
  453.  
  454.     traceline (p1 - f, p2 - f, FALSE, self);
  455.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  456.     {
  457.         particle (trace_endpos, '0 0 100', 225, damage*4);
  458.         T_Damage (trace_ent, from, from, damage);
  459.     }
  460. };
  461.  
  462.  
  463. void() W_FireLightning =
  464. {
  465.     local    vector        org;
  466.  
  467.     if (self.ammo_cells < 1)
  468.     {
  469.         self.weapon = W_BestWeapon ();
  470.         W_SetCurrentAmmo ();
  471.         return;
  472.     }
  473.  
  474. // explode if under water
  475.     if (self.waterlevel > 1)
  476.     {
  477.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  478.         self.ammo_cells = 0;
  479.         W_SetCurrentAmmo ();
  480.         return;
  481.     }
  482.  
  483.     if (self.t_width < time)
  484.     {
  485.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  486.         self.t_width = time + 0.6;
  487.     }
  488.     self.punchangle_x = -2;
  489.  
  490.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  491.  
  492.     org = self.origin + '0 0 16';
  493.     
  494.     traceline (org, org + v_forward*600, TRUE, self);
  495.  
  496.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  497.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  498.     WriteEntity (MSG_BROADCAST, self);
  499.     WriteCoord (MSG_BROADCAST, org_x);
  500.     WriteCoord (MSG_BROADCAST, org_y);
  501.     WriteCoord (MSG_BROADCAST, org_z);
  502.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  503.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  504.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  505.  
  506.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  507. };
  508.  
  509.  
  510. //=============================================================================
  511.  
  512.  
  513. void() GrenadeExplode =
  514. {
  515.     T_RadiusDamage (self, self.owner, 120, world);
  516.  
  517.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  518.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  519.     WriteCoord (MSG_BROADCAST, self.origin_x);
  520.     WriteCoord (MSG_BROADCAST, self.origin_y);
  521.     WriteCoord (MSG_BROADCAST, self.origin_z);
  522.  
  523.     BecomeExplosion ();
  524. };
  525.  
  526. void() GrenadeTouch =
  527. {
  528.     if (other == self.owner)
  529.         return;        // don't explode on owner
  530.     if (other.takedamage == DAMAGE_AIM)
  531.     {
  532.         GrenadeExplode();
  533.         return;
  534.     }
  535.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  536.     if (self.velocity == '0 0 0')
  537.         self.avelocity = '0 0 0';
  538. };
  539.  
  540. /*
  541. ================
  542. W_FireGrenade
  543. ================
  544. */
  545. void() W_FireGrenade =
  546. {
  547.     local    entity missile, mpuff;
  548.     
  549.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  550.     
  551.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  552.  
  553.     self.punchangle_x = -2;
  554.  
  555.     missile = spawn ();
  556.     missile.owner = self;
  557.     missile.movetype = MOVETYPE_BOUNCE;
  558.     missile.solid = SOLID_BBOX;
  559.     missile.classname = "grenade";
  560.         
  561. // set missile speed    
  562.  
  563.     makevectors (self.v_angle);
  564.  
  565.     if (self.v_angle_x)
  566.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  567.     else
  568.     {
  569.         missile.velocity = aim(self, 10000);
  570.         missile.velocity = missile.velocity * 600;
  571.         missile.velocity_z = 200;
  572.     }
  573.  
  574.     missile.avelocity = '300 300 300';
  575.  
  576.     missile.angles = vectoangles(missile.velocity);
  577.     
  578.     missile.touch = GrenadeTouch;
  579.     
  580. // set missile duration
  581.     missile.nextthink = time + 2.5;
  582.     missile.think = GrenadeExplode;
  583.  
  584.     setmodel (missile, "progs/grenade.mdl");
  585.     setsize (missile, '0 0 0', '0 0 0');        
  586.     setorigin (missile, self.origin);
  587. };
  588.  
  589.  
  590. //=============================================================================
  591.  
  592. void() spike_touch;
  593. void() superspike_touch;
  594.  
  595.  
  596. /*
  597. ===============
  598. launch_spike
  599.  
  600. Used for both the player and the ogre
  601. ===============
  602. */
  603. void(vector org, vector dir) launch_spike =
  604. {
  605.     newmis = spawn ();
  606.     newmis.owner = self;
  607.     newmis.movetype = MOVETYPE_FLYMISSILE;
  608.     newmis.solid = SOLID_BBOX;
  609.  
  610.     newmis.angles = vectoangles(dir);
  611.     
  612.     newmis.touch = spike_touch;
  613.     newmis.classname = "spike";
  614.     newmis.think = SUB_Remove;
  615.     newmis.nextthink = time + 6;
  616.     setmodel (newmis, "progs/spike.mdl");
  617.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  618.     setorigin (newmis, org);
  619.  
  620.     newmis.velocity = dir * 1000;
  621. };
  622.  
  623. void() W_FireSuperSpikes =
  624. {
  625.     local vector    dir;
  626.     local entity    old;
  627.     
  628.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  629.     self.attack_finished = time + 0.2;
  630.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  631.     dir = aim (self, 1000);
  632.     launch_spike (self.origin + '0 0 16', dir);
  633.     newmis.touch = superspike_touch;
  634.     setmodel (newmis, "progs/s_spike.mdl");
  635.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  636.     self.punchangle_x = -2;
  637. };
  638.  
  639. //Spread Nailgun
  640. void(vector split) W_FireSpreadSpikes =
  641. {
  642.     local vector    dir;
  643.     local entity    old;
  644.     
  645.     makevectors (self.v_angle);
  646.     
  647.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  648.         self.attack_finished = time + 0.8;
  649.         self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  650.     dir = aim (self, 1000);
  651.  
  652.         //Spread Nailgun
  653.     //Fire a spread of nails in a 5 x 5 cross pattern
  654.  
  655.         local float shotcount;
  656.         shotcount = 5;
  657.         local float spread;    
  658.         local float density;
  659.         density = 0.06;
  660.         spread = floor ( shotcount / 2 );
  661.         spread = spread * density * -1;
  662.         while (shotcount > 0)
  663.         {
  664.                 launch_spike (self.origin + '0 0 16', dir + spread * split);
  665.                 spread = spread + density;
  666.                 shotcount = shotcount - 1;
  667.         }
  668.         
  669.     self.punchangle_x = -2;
  670. };   
  671.  
  672. void(float ox) W_FireSpikes =
  673. {
  674.     local vector    dir;
  675.     local entity    old;
  676.     
  677.     makevectors (self.v_angle);
  678.     
  679.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  680.     {
  681.         W_FireSuperSpikes ();
  682.         return;
  683.     }
  684.  
  685.     if (self.ammo_nails >= 2 && self.weapon == IT_SPREAD_NAILGUN)
  686.     {
  687.                 if (ox > 0)
  688.             W_FireSpreadSpikes (v_right);
  689.                 if (ox < 0)
  690.             W_FireSpreadSpikes (v_up);
  691.         return;
  692.     }
  693.  
  694.     if (self.ammo_nails < 1)
  695.     {
  696.         self.weapon = W_BestWeapon ();
  697.         W_SetCurrentAmmo ();
  698.         return;
  699.     }
  700.  
  701.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  702.     self.attack_finished = time + 0.2;
  703.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  704.     dir = aim (self, 1000);
  705.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  706.  
  707.     self.punchangle_x = -2;
  708. };
  709.  
  710.  
  711. .float hit_z;
  712. void() spike_touch =
  713. {
  714. local float rand;
  715.     if (other == self.owner)
  716.         return;
  717.  
  718.     if (other.solid == SOLID_TRIGGER)
  719.         return;    // trigger field, do nothing
  720.  
  721.     if (pointcontents(self.origin) == CONTENT_SKY)
  722.     {
  723.         remove(self);
  724.         return;
  725.     }
  726.     
  727. // hit something that bleeds
  728.     if (other.takedamage)
  729.     {
  730.         spawn_touchblood (9);
  731.         T_Damage (other, self, self.owner, 9);
  732.     }
  733.     else
  734.     {
  735.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  736.         
  737.         if (self.classname == "wizspike")
  738.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  739.         else if (self.classname == "knightspike")
  740.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  741.         else
  742.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  743.         WriteCoord (MSG_BROADCAST, self.origin_x);
  744.         WriteCoord (MSG_BROADCAST, self.origin_y);
  745.         WriteCoord (MSG_BROADCAST, self.origin_z);
  746.     }
  747.  
  748.     remove(self);
  749.  
  750. };
  751.  
  752. void() superspike_touch =
  753. {
  754. local float rand;
  755.     if (other == self.owner)
  756.         return;
  757.  
  758.     if (other.solid == SOLID_TRIGGER)
  759.         return;    // trigger field, do nothing
  760.  
  761.     if (pointcontents(self.origin) == CONTENT_SKY)
  762.     {
  763.         remove(self);
  764.         return;
  765.     }
  766.     
  767. // hit something that bleeds
  768.     if (other.takedamage)
  769.     {
  770.         spawn_touchblood (18);
  771.         T_Damage (other, self, self.owner, 18);
  772.     }
  773.     else
  774.     {
  775.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  776.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  777.         WriteCoord (MSG_BROADCAST, self.origin_x);
  778.         WriteCoord (MSG_BROADCAST, self.origin_y);
  779.         WriteCoord (MSG_BROADCAST, self.origin_z);
  780.     }
  781.  
  782.     remove(self);
  783.  
  784. };
  785.  
  786.  
  787. /*
  788. ===============================================================================
  789.  
  790. PLAYER WEAPON USE
  791.  
  792. ===============================================================================
  793. */
  794.  
  795. void() W_SetCurrentAmmo =
  796. {
  797.     player_run ();        // get out of any weapon firing states
  798.  
  799.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  800.     
  801.     if (self.weapon == IT_AXE)
  802.     {
  803.         self.currentammo = 0;
  804.         self.weaponmodel = "progs/v_axe.mdl";
  805.         self.weaponframe = 0;
  806.     }
  807.     else if (self.weapon == IT_SHOTGUN)
  808.     {
  809.         self.currentammo = self.ammo_shells;
  810.         self.weaponmodel = "progs/v_shot.mdl";
  811.         self.weaponframe = 0;
  812.         self.items = self.items | IT_SHELLS;
  813.     }
  814.     else if (self.weapon == IT_SUPER_SHOTGUN)
  815.     {
  816.         self.currentammo = self.ammo_shells;
  817.         self.weaponmodel = "progs/v_shot2.mdl";
  818.         self.weaponframe = 0;
  819.         self.items = self.items | IT_SHELLS;
  820.     }
  821.     else if (self.weapon == IT_NAILGUN)
  822.     {
  823.         self.currentammo = self.ammo_nails;
  824.         self.weaponmodel = "progs/v_nail.mdl";
  825.         self.weaponframe = 0;
  826.         self.items = self.items | IT_NAILS;
  827.     }
  828.     else if (self.weapon == IT_SUPER_NAILGUN)
  829.     {
  830.         self.currentammo = self.ammo_nails;
  831.         self.weaponmodel = "progs/v_nail2.mdl";
  832.         self.weaponframe = 0;
  833.         self.items = self.items | IT_NAILS;
  834.     }
  835.     // Spread Nailgun
  836.     else if (self.weapon == IT_SPREAD_NAILGUN)
  837.     {
  838.         self.currentammo = self.ammo_nails;
  839.         self.weaponmodel = "progs/v_nail2.mdl";
  840.         self.weaponframe = 0;
  841.         self.items = self.items | IT_NAILS;
  842.     }
  843.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  844.     {
  845.         self.currentammo = self.ammo_rockets;
  846.         self.weaponmodel = "progs/v_rock.mdl";
  847.         self.weaponframe = 0;
  848.         self.items = self.items | IT_ROCKETS;
  849.     }
  850.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  851.     {
  852.         self.currentammo = self.ammo_rockets;
  853.         self.weaponmodel = "progs/v_rock2.mdl";
  854.         self.weaponframe = 0;
  855.         self.items = self.items | IT_ROCKETS;
  856.     }
  857.     else if (self.weapon == IT_LIGHTNING)
  858.     {
  859.         self.currentammo = self.ammo_cells;
  860.         self.weaponmodel = "progs/v_light.mdl";
  861.         self.weaponframe = 0;
  862.         self.items = self.items | IT_CELLS;
  863.     }
  864.     else
  865.     {
  866.         self.currentammo = 0;
  867.         self.weaponmodel = "";
  868.         self.weaponframe = 0;
  869.     }
  870. };
  871.  
  872. float() W_BestWeapon =
  873. {
  874.     local    float    it;
  875.     
  876.     it = self.items;
  877.  
  878.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  879.         return IT_LIGHTNING;
  880.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  881.         return IT_SUPER_NAILGUN;
  882.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  883.         return IT_SUPER_SHOTGUN;
  884.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  885.         return IT_NAILGUN;
  886.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  887.         return IT_SHOTGUN;
  888.         
  889. /*
  890.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  891.         return IT_ROCKET_LAUNCHER;
  892.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  893.         return IT_GRENADE_LAUNCHER;
  894.  
  895. */
  896.  
  897.     return IT_AXE;
  898. };
  899.  
  900. float() W_CheckNoAmmo =
  901. {
  902.     if (self.currentammo > 0)
  903.         return TRUE;
  904.  
  905.     if (self.weapon == IT_AXE)
  906.         return TRUE;
  907.     
  908.     self.weapon = W_BestWeapon ();
  909.  
  910.     W_SetCurrentAmmo ();
  911.     
  912. // drop the weapon down
  913.     return FALSE;
  914. };
  915.  
  916. /*
  917. ============
  918. W_Attack
  919.  
  920. An attack impulse can be triggered now
  921. ============
  922. */
  923. void()    player_axe1;
  924. void()    player_axeb1;
  925. void()    player_axec1;
  926. void()    player_axed1;
  927. void()    player_shot1;
  928. void()    player_nail1;
  929. void()    player_light1;
  930. void()    player_rocket1;
  931.  
  932. void() W_Attack =
  933. {
  934.     local    float    r;
  935.  
  936.     if (!W_CheckNoAmmo ())
  937.         return;
  938.  
  939.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  940.     self.show_hostile = time + 1;    // wake monsters up
  941.  
  942.     if (self.weapon == IT_AXE)
  943.     {
  944.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  945.         r = random();
  946.         if (r < 0.25)
  947.             player_axe1 ();
  948.         else if (r<0.5)
  949.             player_axeb1 ();
  950.         else if (r<0.75)
  951.             player_axec1 ();
  952.         else
  953.             player_axed1 ();
  954.         self.attack_finished = time + 0.5;
  955.     }
  956.     else if (self.weapon == IT_SHOTGUN)
  957.     {
  958.         player_shot1 ();
  959.         W_FireShotgun ();
  960.         self.attack_finished = time + 0.5;
  961.     }
  962.     else if (self.weapon == IT_SUPER_SHOTGUN)
  963.     {
  964.         player_shot1 ();
  965.         W_FireSuperShotgun ();
  966.         self.attack_finished = time + 0.7;
  967.     }
  968.     else if (self.weapon == IT_NAILGUN)
  969.     {
  970.         player_nail1 ();
  971.     }
  972.     else if (self.weapon == IT_SUPER_NAILGUN)
  973.     {
  974.         player_nail1 ();
  975.     }
  976.  
  977.     // Spread Nailgun
  978.     else if (self.weapon == IT_SPREAD_NAILGUN)
  979.     {
  980.         player_nail1 ();
  981.         }
  982.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  983.     {
  984.         player_rocket1();
  985.         W_FireGrenade();
  986.         self.attack_finished = time + 0.6;
  987.     }
  988.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  989.     {
  990.         player_rocket1();
  991.         W_FireRocket();
  992.         self.attack_finished = time + 0.8;
  993.     }
  994.     else if (self.weapon == IT_LIGHTNING)
  995.     {
  996.         player_light1();
  997.         self.attack_finished = time + 0.1;
  998.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  999.     }
  1000. };
  1001.  
  1002. /*
  1003. ============
  1004. W_ChangeWeapon
  1005.  
  1006. ============
  1007. */
  1008. void() W_ChangeWeapon =
  1009. {
  1010.     local    float    it, am, fl;
  1011.     
  1012.     it = self.items;
  1013.     am = 0;
  1014.     
  1015.     if (self.impulse == 1)
  1016.     {
  1017.         fl = IT_AXE;
  1018.     }
  1019.     else if (self.impulse == 2)
  1020.     {
  1021.         fl = IT_SHOTGUN;
  1022.         if (self.ammo_shells < 1)
  1023.             am = 1;
  1024.     }
  1025.     else if (self.impulse == 3)
  1026.     {
  1027.         fl = IT_SUPER_SHOTGUN;
  1028.         if (self.ammo_shells < 2)
  1029.             am = 1;
  1030.     }        
  1031.     else if (self.impulse == 4)
  1032.     {
  1033.         if (self.weapon != IT_NAILGUN)
  1034.                 {
  1035.                         fl = IT_NAILGUN;
  1036.                         if (self.ammo_nails < 1)
  1037.                                 am = 1;
  1038.                 }
  1039.                 else if (self.weapon = IT_NAILGUN)
  1040.                 {
  1041.                         fl = IT_SPREAD_NAILGUN;
  1042.                         if (self.ammo_nails < 2)
  1043.                                 am = 1;
  1044.                 }
  1045.                 else am = 1;
  1046.     }
  1047.     else if (self.impulse == 5)
  1048.     {
  1049.         fl = IT_SUPER_NAILGUN;
  1050.         if (self.ammo_nails < 2)
  1051.             am = 1;
  1052.     }
  1053.     else if (self.impulse == 6)
  1054.     {
  1055.         fl = IT_GRENADE_LAUNCHER;
  1056.         if (self.ammo_rockets < 1)
  1057.             am = 1;
  1058.     }
  1059.     else if (self.impulse == 7)
  1060.     {
  1061.         fl = IT_ROCKET_LAUNCHER;
  1062.         if (self.ammo_rockets < 1)
  1063.             am = 1;
  1064.     }
  1065.     else if (self.impulse == 8)
  1066.     {
  1067.         fl = IT_LIGHTNING;
  1068.         if (self.ammo_cells < 1)
  1069.             am = 1;
  1070.     }
  1071.     else if (self.impulse == 50)
  1072.     {
  1073.         fl = IT_SPREAD_NAILGUN;
  1074.         if (self.ammo_nails < 2)
  1075.             am = 1;
  1076.     }
  1077.  
  1078.     self.impulse = 0;
  1079.     
  1080.     if (!(self.items & fl))
  1081.     {    // don't have the weapon or the ammo
  1082.         sprint (self, "no weapon.\n");
  1083.         return;
  1084.     }
  1085.     
  1086.     if (am)
  1087.     {    // don't have the ammo
  1088.         sprint (self, "not enough ammo.\n");
  1089.         return;
  1090.     }
  1091.  
  1092. //
  1093. // set weapon, set ammo
  1094. //
  1095.     self.weapon = fl;
  1096.     if (self.weapon == IT_SPREAD_NAILGUN)
  1097.         sprint (self, "Spread Nailgun \n");
  1098.     if (self.weapon == IT_NAILGUN)
  1099.                 sprint (self,"Nailgun\n");
  1100.  
  1101.     W_SetCurrentAmmo ();
  1102. };
  1103.  
  1104. /*
  1105. ============
  1106. CheatCommand
  1107. ============
  1108. */
  1109. void() CheatCommand =
  1110. {
  1111.     if (deathmatch || coop)
  1112.         return;
  1113.  
  1114.     self.ammo_rockets = 100;
  1115.     self.ammo_nails = 200;
  1116.     self.ammo_shells = 100;
  1117.     self.items = self.items | 
  1118.         IT_AXE |
  1119.         IT_SHOTGUN |
  1120.         IT_SUPER_SHOTGUN |
  1121.         IT_NAILGUN |
  1122.         IT_SUPER_NAILGUN |
  1123.         IT_SPREAD_NAILGUN |
  1124.         IT_GRENADE_LAUNCHER |
  1125.         IT_ROCKET_LAUNCHER |
  1126.         IT_KEY1 | IT_KEY2;
  1127.  
  1128.     self.ammo_cells = 200;
  1129.     self.items = self.items | IT_LIGHTNING;
  1130.  
  1131.     self.weapon = IT_ROCKET_LAUNCHER;
  1132.     self.impulse = 0;
  1133.     W_SetCurrentAmmo ();
  1134. };
  1135.  
  1136. /*
  1137. ============
  1138. CycleWeaponCommand
  1139.  
  1140. Go to the next weapon with ammo
  1141. ============
  1142. */
  1143. void() CycleWeaponCommand =
  1144. {
  1145.     local    float    it, am;
  1146.     
  1147.     it = self.items;
  1148.     self.impulse = 0;
  1149.     
  1150.     while (1)
  1151.     {
  1152.         am = 0;
  1153.  
  1154.         if (self.weapon == IT_LIGHTNING)
  1155.         {
  1156.             self.weapon = IT_AXE;
  1157.         }
  1158.         else if (self.weapon == IT_AXE)
  1159.         {
  1160.             self.weapon = IT_SHOTGUN;
  1161.             if (self.ammo_shells < 1)
  1162.                 am = 1;
  1163.         }
  1164.         else if (self.weapon == IT_SHOTGUN)
  1165.         {
  1166.             self.weapon = IT_SUPER_SHOTGUN;
  1167.             if (self.ammo_shells < 2)
  1168.                 am = 1;
  1169.         }        
  1170.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1171.         {
  1172.             self.weapon = IT_NAILGUN;
  1173.             if (self.ammo_nails < 1)
  1174.                 am = 1;
  1175.         }
  1176.         else if (self.weapon == IT_NAILGUN)
  1177.         {    self.weapon = IT_SPREAD_NAILGUN;
  1178.             if (self.ammo_nails < 1)
  1179.                 am = 1;
  1180.         }
  1181.                 else if (self.weapon == IT_SPREAD_NAILGUN)
  1182.         {
  1183.             self.weapon = IT_SUPER_NAILGUN;
  1184.             if (self.ammo_nails < 2)
  1185.                 am = 1;
  1186.         }
  1187.         else if (self.weapon == IT_SUPER_NAILGUN)
  1188.         {
  1189.             self.weapon = IT_GRENADE_LAUNCHER;
  1190.             if (self.ammo_rockets < 1)
  1191.                 am = 1;
  1192.         }
  1193.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1194.         {
  1195.             self.weapon = IT_ROCKET_LAUNCHER;
  1196.             if (self.ammo_rockets < 1)
  1197.                 am = 1;
  1198.         }
  1199.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1200.         {
  1201.             self.weapon = IT_LIGHTNING;
  1202.             if (self.ammo_cells < 1)
  1203.                 am = 1;
  1204.         }
  1205.     
  1206.         if ( (self.items & self.weapon) && am == 0)
  1207.         {
  1208.             if (self.weapon == IT_SPREAD_NAILGUN)
  1209.                 sprint (self, "Spread Nailgun \n");
  1210.             if (self.weapon == IT_NAILGUN)
  1211.                         sprint (self,"Nailgun\n");
  1212.  
  1213.             W_SetCurrentAmmo ();
  1214.             return;
  1215.         }
  1216.     }
  1217.  
  1218. };
  1219.  
  1220. /*
  1221. ============
  1222. ServerflagsCommand
  1223.  
  1224. Just for development
  1225. ============
  1226. */
  1227. void() ServerflagsCommand =
  1228. {
  1229.     serverflags = serverflags * 2 + 1;
  1230. };
  1231.  
  1232. void() QuadCheat =
  1233. {
  1234.     if (deathmatch || coop)
  1235.         return;
  1236.     self.super_time = 1;
  1237.     self.super_damage_finished = time + 30;
  1238.     self.items = self.items | IT_QUAD;
  1239.     dprint ("quad cheat\n");
  1240. };
  1241.  
  1242. /*
  1243. ============
  1244. ImpulseCommands
  1245.  
  1246. ============
  1247. */
  1248. void() ImpulseCommands =
  1249. {
  1250.     if (self.impulse >= 1 && self.impulse <= 8)
  1251.         W_ChangeWeapon ();
  1252.  
  1253.     if (self.impulse == 9)
  1254.         CheatCommand ();
  1255.     if (self.impulse == 10)
  1256.         CycleWeaponCommand ();
  1257.     if (self.impulse == 11)
  1258.         ServerflagsCommand ();
  1259.  
  1260.     if (self.impulse == 255)
  1261.         QuadCheat ();
  1262.         
  1263.     self.impulse = 0;
  1264. };
  1265.  
  1266. /*
  1267. ============
  1268. W_WeaponFrame
  1269.  
  1270. Called every frame so impulse events can be handled as well as possible
  1271. ============
  1272. */
  1273. void() W_WeaponFrame =
  1274. {
  1275.     if (time < self.attack_finished)
  1276.         return;
  1277.  
  1278.     ImpulseCommands ();
  1279.     
  1280. // check for attack
  1281.     if (self.button0)
  1282.     {
  1283.         SuperDamageSound ();
  1284.         W_Attack ();
  1285.     }
  1286. };
  1287.  
  1288. /*
  1289. ========
  1290. SuperDamageSound
  1291.  
  1292. Plays sound if needed
  1293. ========
  1294. */
  1295. void() SuperDamageSound =
  1296. {
  1297.     if (self.super_damage_finished > time)
  1298.     {
  1299.         if (self.super_sound < time)
  1300.         {
  1301.             self.super_sound = time + 1;
  1302.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1303.         }
  1304.     }
  1305.     return;
  1306. };
  1307.  
  1308.  
  1309.